using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraManager : MonoBehaviour
{
    // 回调函数
    public delegate void OnActiveCameraChangedCallback();
    public OnActiveCameraChangedCallback[] OnActiveCameraChanged;

    // 所有相机
    public GameObject[] cameras;

    // 当前生效的相机
    private int activeCamera = 0;

    // singleton
    public static CameraManager instance;
    void Awake()
    {
        instance = this;
    }

    private void Start()
    {
        cameras[0].GetComponent<Camera>().enabled = true;
        for (int i = 1; i < cameras.Length; i++)
        {
            cameras[i].GetComponent<Camera>().enabled = true;
        }
    }

    // 获取当前相机
    public GameObject GetActiveCamera()
    {
        return cameras[activeCamera];
    }

    // 更改当前相机
    public void SwitchCamera(int idx)
    {
        cameras[activeCamera].GetComponent<Camera>().enabled = false;
        activeCamera = idx;
        cameras[activeCamera].GetComponent<Camera>().enabled = true;

        foreach (var callback in OnActiveCameraChanged)
        {
            callback();
        }
    }
}